<table width="100%" border="0" cellpadding="0" cellspacing="0" >
  <tr><td colspan="3" bgcolor="#333333"></td></tr>
  <tr>
    <td width="77%" valign="top" style="padding-left:10px;padding-top:10px ">
<?
	$url=$_SERVER['HTTP_HOST'].$_SERVER['QUERY_STRING']; 
	if (eregi("memproducts.php",$url)) {	
		die("&nbsp;");
	}
	//check_gpc();
	 
	$template_products_body="template/memproduct_list.tpl";
	$template_proDetail="template/memProductDetail.tpl";
	$base_url 	= 'supplier.php';
	
	//tri: $tagPro lấy từ trang supplier.php
	 switch($mode){ 
	  case "productDetail":
		  productDetail();
		  break;
	  case "main":
		 if($tagPro == 0) redirect($base_url);
			else mainproducts();
		//mainproducts();
		break;
	  default:
		  viewProduct(); 
		  break;
	 }
	 
function productDetail(){
	global $template, $db, $template_proDetail,$cid,$site_base_href,$catID,$keyw,$ids ;
	
	$proid=isset($_GET["pid"]) ? $_GET["pid"] : 0;
	
	 $sql="select  m.memID, m.FirstName, m.LastName, m.CompanyName, m.Sex, 
	m.AlternativeEmail,m. BusinessType, m.IndustryCategory, m.NumberEmployees, m.Address, m.City, 
	m.State, m.Zip, m.Web, m.JobTitle, m.contrycode, m.areacode, m.BusinessPhone, m.faxcontrycode, 
	m.faxareacode, m.FaxNumber, m.Mobile, m.fName, m.countryID, m.orthJob, m.lName, 
	 m.CompanyName_vn, m.Address_vn, m.fName_vn,  m.lName_vn, m.FirstName_vn, m.LastName_vn, m.City_vn,
	 m.State_vn, m.orthJob_vn, m.lastEdit,  m.lastEdit_vn, m.id,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!","",__LINE__,__FILE__,$sql);	 
	}	
	$mem_data=$db->sql_fetchrow($result);		
	
	$sql="select * from vb_products where  proID=".$proid;	 
	if(!$result=$db->sql_query($sql)){
	 // message_die("Couldn't run the sql query!","",__LINE__,__FILE__,$sql);
		 mainproducts(); 
		 return;
	}
	
	$pro_data=$db->sql_fetchrow($result);	
	
	$simages='<img src="products/'.$pro_data["images180"].'" border="0" class="imageborder">';
	if(!ereg(".jpg",$pro_data["images180"]) && !ereg(".gif",$pro_data["images180"]) ){				 	
		//$simages='<img src="images/no_photo.gif" class="imageborder">';
		$simages='';
	}
	$memName=$mem_data["fName"] ."&nbsp;". $mem_data["lName"] ;
	$template->assign_vars(array(			
		 'productDetail'=>'<a href="supplier.php?supplier='.$cid.'&act=products&catID='.$pro_data["proID"].'&ids='.$ids.'&lang=us" class="ca">'.$pro_data["Keywords"].'</a> > '. $pro_data["ProductName"],
		 'companyName'	=>  $mem_data["CompanyName"],		 
		 'maintitle'		=> $mem_data["CompanyName"] .'  -  yellowpages.vn | Vietnam', 
		 'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\">" : '' , 
		 'viewlarger' => '<a href="javascript:void(0)" class="lMenu" onClick="openwin(\'largerImage.php?img='.$pro_data["Images"].'&imgn='. urlencode($pro_data["ProductName"]).'\',120,120)">View Larger Picture</a>',
		 'proName'	=> $pro_data["ProductName"],
		 'ProModel' 	=> !empty($pro_data["Model"]) ? 'Model Number :'. $pro_data["Model"] : '',
		 'supp'	=>$cid,
		 'proDescription'	=>html_entity_decode(nl2br($pro_data["Description"])),
		 'photo'	=> '<a href="javascript:void(0)" class="lMenu" onClick="openwin(\'largerImage.php?img='.$pro_data["Images"].'&imgn='. urlencode($pro_data["ProductName"]).'\',120,120)">'.$simages.'</a>',
		 'nophoto' => $simages ? ' ' : 'style="display:none"',
		 'company'	=> $mem_data["CompanyName"],
		 'ContactName'	=>($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") .$memName ,
		 'Address'	=>$mem_data["Address"],
		 'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
		 'zipCode'	=>$mem_data["Zip"],
		 'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
		 'mobiphone'	=>$mem_data["Mobile"],
		 'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
		 'Website'	=>$mem_data["Web"],		
		 'a_action' =>"supplier.php?supplier=".$cid."&act=memcontacts&mode=main&ids=".$ids."&lang=us",		 
		 'lid'		=>$proid,
		 'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
		 'detaildis'  =>!empty($pro_data["Description"]) ? 'bock' : 'none',
		 'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
		 'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
		 'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
		 'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		));
	$template->set_filenames(array(
		"body"	=> $template_proDetail
	));
	$template->pparse('body');
} 
function viewProduct(){
	global $template, $db, $template_products_body,$catID,$cid,$keyw,$site_base_href,$base_url,$langUrl,$ids ;
	
	$start	 = isset($_GET["start"]) ? intval($_GET["start"]) : 0;
	$txtgoto = isset($_POST['txtgoto']) ? intval($_POST['txtgoto']) : 0; 
	
	$display=15;
	 if($txtgoto){
		$start	=  floor($txtgoto*$display)-1; 		
	 }

	
	$sql="select * from vb_products where proActive=1 and memID=".$cid."  and Keywords='$keyw' limit $start,$display" ;
	// echo $sql ; die() ;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	
	 
	$sql = "SELECT count(proID) AS total FROM vb_products where proActive=1 and memID=".$cid."  and Keywords='$keyw'" ;
	if ( !$result = $db->sql_query($sql) ) {
		message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
	}
	
	$total 			= $db->sql_fetchrow($result);

	$pagination 	= g3_pagination("supplier.php?supplier=".$cid."&act=products&catID=".$catID."&ids=".$ids."&lang=us", $total['total'], $display, $start, 'start', 'Page ' . '//<img src="images/prev.gif" border="0">//<img src="images/next.gif" border="0">')."&nbsp;";
	$total_pages = ceil($total['total']/$display);
 
	$db->sql_freeresult($result);
	
		for ($i=0; $i<$pro_count; $i++){			
			$simages='<img src="products/'.$pro_data[$i]["sImages"].'" class="imageborder">';
				if(!ereg(".jpg",$pro_data[$i]["sImages"]) && !ereg(".gif",$pro_data[$i]["sImages"]) ){				 	
					$simages='<img src="images/no_photo.gif" class="imageborder">';
				}
				$detail=html_entity_decode(nl2br($pro_data[$i]["Description"]));
				$arrStr=explode(' ',$detail);				
				$k= count($arrStr)<18 ? count($arrStr) : 18;				
				$detail='';
				  for($j=0;$j<$k;$j++){
					   $detail.=$arrStr[$j].' ';
					 }
				if($k==18){
				 $detail.=' ...';
				}	 
				
			$template->assign_block_vars("productList", array(							
				'pname'	 => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="proLink">'.$pro_data[$i]["ProductName"].'</a>',
				'photo' => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="proLink">'.$simages.'</a>',
				'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$pro_data[$i]["proID"].']" value="'.$pro_data[$i]["proID"].'"/>',
				'model'	=> 	$pro_data[$i]["Model"] ? 'Model No : '.	$pro_data[$i]["Model"] : "&nbsp;",
				'pdetail'		 =>	$detail
			));
	  } 
	  
	$sql="select  m.memID, m.FirstName, m.LastName, m.CompanyName, m.Sex, 
	m.AlternativeEmail,m. BusinessType, m.IndustryCategory, m.NumberEmployees, m.Address, m.City, 
	m.State, m.Zip, m.Web, m.JobTitle, m.contrycode, m.areacode, m.BusinessPhone, m.faxcontrycode, 
	m.faxareacode, m.FaxNumber, m.Mobile, m.fName, m.countryID, m.orthJob, m.lName, 
	 m.CompanyName_vn, m.Address_vn, m.fName_vn,  m.lName_vn, m.FirstName_vn, m.LastName_vn, m.City_vn,
	 m.State_vn, m.orthJob_vn, m.lastEdit,  m.lastEdit_vn, m.id,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	
	$mem_data=$db->sql_fetchrow($result);		
	
	$memName=$mem_data["fName"] ."&nbsp;". $mem_data["lName"] ;
	$template->assign_vars(array(			 
		'barner'	=>  "barner/".$mem_data["barner"],
		'companyName'	=>  $mem_data["CompanyName"],			
		'maintitle'		=>$mem_data["CompanyName"] .'  -  yellowpages.vn | Vietnam',  
		'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\">" : '' ,		 
		'supp'	=>$cid,
		'company'	=> $mem_data["CompanyName"],
		'ContactName'	=> ($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") .$memName,
		'Address'	=>$mem_data["Address"],
		'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
		'zipCode'	=>$mem_data["Zip"],
		'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
		'mobiphone'	=>$mem_data["Mobile"],
		'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
		'Website'	=>$mem_data["Web"],
		'a_action' =>"supplier.php?supplier=".$cid."&act=memcontacts&catID=".$catID."&ids=".$ids."&lang=us",
		'NAVIGATOR'     => $pagination,
		'navidis'  => $total_pages >1 ? 'display' : 'none',
		'g_action' =>"supplier.php?supplier=".$cid."&act=products&catID=".$catID."&ids=".$ids."&lang=us",
		'Products'	=>'Products > '.$keyw,		
		'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
		'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
		'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
		'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
		'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		'oldurl' =>$langUrl
		 
	));
		
	$template->set_filenames(array(
		"body"	=> $template_products_body
	));
	$template->pparse('body');
}
function mainproducts(){
	global $template, $db, $template_products_body,$catID,$cid,$keyw,$site_base_href,$base_url,$langUrl,$ids ;
	$start		= isset($_GET["start"]) ? intval($_GET["start"]) : 0;
	$txtgoto=isset($_POST['txtgoto']) ? intval($_POST['txtgoto']) : 0; 
	
	$display=15;
	 if($txtgoto){
		$start	=  floor(($txtgoto-1)*$display); 		
		//$start	=  floor($txtgoto*$display)-1; 		
	}
	 
	$sql="select * from vb_products where proActive=1 and memID=".$cid."  order by Keywords limit $start,$display" ;
	
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}
	$pro_count=$db->sql_numrows($result);
	$pro_data=$db->sql_fetchrowset($result);	

	
	$sql = "SELECT count(proID) AS total FROM vb_products where proActive=1 and memID=".$cid."  order by  Keywords" ;
	if ( !$result = $db->sql_query($sql) ) {
		message_die("Couldn't run the sql query!!!", __LINE__, __FILE__, $sql);
	}
	$total 	= $db->sql_fetchrow($result);
	
	if($total['total']<1){
	  echo '<br>There are no product in database<br><br>';
		return;
	}
		
	$pagination = g3_pagination("supplier.php?supplier=".$cid."&act=products&mode=main&ids=".$ids."&lang=us", $total['total'], $display, $start, 'start', 'Page:' . '//<img src="images/prev.gif" border="0">//<img src="images/next.gif" border="0">')."&nbsp;";
	$total_pages = ceil($total['total']/$display);
	$db->sql_freeresult($result);
	
		for ($i=0; $i<$pro_count; $i++){	
				$simages='<img src="products/'.$pro_data[$i]["sImages"].'" class="imageborder">';
				if(!ereg(".jpg",$pro_data[$i]["sImages"]) && !ereg(".gif",$pro_data[$i]["sImages"]) ){				 	
					$simages='<img src="images/no_photo.gif" class="imageborder">';
				}
				
				$detail=html_entity_decode(nl2br($pro_data[$i]["Description"]));
				$arrStr=explode(' ',$detail);				
				$k= count($arrStr)<18 ? count($arrStr) : 18;				
				$detail='';
				  for($j=0;$j<$k;$j++){
					   $detail.=$arrStr[$j].' ';
				  }
				if($k==18){
				 $detail.=' ...';
				}	 
	$template->assign_block_vars("productList", array(	
		'pname'	 => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="proLink">'.$pro_data[$i]["ProductName"].'</a>',
		'photo' => '<a href="supplier.php?supplier='.$pro_data[$i]["memID"].'&act=products&mode=productDetail&pid='.$pro_data[$i]["proID"] .'&catID='.$pro_data[$i]["catID"].'&ids='.$ids.'&lang=us" class="proLink">'.$simages.'</a>',	
		'CHECKBOX'	 => '<input type="Checkbox" name="proid['.$pro_data[$i]["proID"].']" value="'.$pro_data[$i]["proID"].'"/>',
		'model'	=> 	$pro_data[$i]["Model"] ? 'Model No : '.	$pro_data[$i]["Model"] : "&nbsp;",'pdetail'	=>$detail 
	));
	  }
	  
	$sql="select  m.memID, m.FirstName, m.LastName, m.CompanyName, m.Sex, 
	m.AlternativeEmail,m. BusinessType, m.IndustryCategory, m.NumberEmployees, m.Address, m.City, 
	m.State, m.Zip, m.Web, m.JobTitle, m.contrycode, m.areacode, m.BusinessPhone, m.faxcontrycode, 
	m.faxareacode, m.FaxNumber, m.Mobile, m.fName, m.countryID, m.orthJob, m.lName, 
	 m.CompanyName_vn, m.Address_vn, m.fName_vn,  m.lName_vn, m.FirstName_vn, m.LastName_vn, m.City_vn,
	 m.State_vn, m.orthJob_vn, m.lastEdit,  m.lastEdit_vn, m.id,c.* from vb_companyprofile c inner join vb_memberprofile m on c.memID=m.memID where c.memID=".$cid;
	if(!$result=$db->sql_query($sql)){
	  message_die("Couldn't run the sql query!!!","",__LINE__,__FILE__,$sql);
	}	
	$mem_data=$db->sql_fetchrow($result);		
	$memName=$mem_data["fName"] ."&nbsp;". $mem_data["lName"] ;
	
	$template->assign_vars(array(				 
		'barner'	=>  "barner/".$mem_data["barner"],
		'Products'	=>'Products',
		'companyName'	=>  $mem_data["CompanyName"],		 
		'com_photo'	=> !empty($mem_data["barner"]) ? "<img src=\"barner/".$mem_data["barner"]."\">" : '' ,
		'supp'	=>$cid,
		'maintitle'		=>$mem_data["CompanyName"] .'  -  yellowpages.vn | Vietnam', 
		'company'	=> $mem_data["CompanyName"],
		'ContactName'	=>($mem_data["Sex"]=="Male" ? "Mr. " : "Ms. ") . $memName,
		'Address'	=>$mem_data["Address"],
		'city'		=>$mem_data["City"].", ".getContry($mem_data["countryID"]),
		'zipCode'	=>$mem_data["Zip"],
		'Telephone'	=>  $mem_data["contrycode"] ."-".$mem_data["areacode"]."-".$mem_data["BusinessPhone"],
		'mobiphone'	=>$mem_data["Mobile"],
		'fax'	=>$mem_data["faxcontrycode"] ."-".$mem_data["faxareacode"]."-".$mem_data["FaxNumber"],
		'Website'	=>$mem_data["Web"],
		'a_action' =>"supplier.php?supplier=".$cid."&act=memcontacts&mode=main&ids=".$ids."&lang=us",
		'NAVIGATOR'     => $pagination,
		'g_action' =>"supplier.php?supplier=".$cid."&act=products&mode=main&ids=".$ids."&lang=us",
		'divtel'	=> !empty($mem_data["BusinessPhone"]) ? 'bock' : 'none',
		'divmobi'	=> !empty($mem_data["Mobile"]) ? 'bock' : 'none',
		'divfax' => !empty($mem_data["FaxNumber"]) ? 'bock' : 'none',
		'divweb' => !empty($mem_data["Web"]) ? 'bock' : 'none',
		'divcontactName' =>strlen($memName)>9 ? 'bock' : 'none',
		'navidis'  => $total_pages >1 ? 'display' : 'none',
		'oldurl' =>$langUrl
	));
		 
	$template->set_filenames(array(
		"body"	=> $template_products_body
	));
	$template->pparse('body');
}

?></td>
	<td  bgcolor="#333333"></td>
    <td width="23%" valign="top" style="padding-top:10px ">
	<table width="200" border="0">
      <tr>
        <td style="padding-left:10px "><strong>Categories</strong></td>
      </tr>
      <tr>
        <td style="padding-left:10px "><? include "uproducts.php"?></td>
      </tr>
    </table>
  	</td>
  </tr>
  <tr>
    <td colspan="2"></td>
  </tr>
</table>		